package com.levi.config;

import com.levi.filter.CustomGatewayFilter;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 自定义过滤器配置类
 */
@Configuration
public class GatewayRoutesConfiguration {

    @Bean
    public RouteLocator routeLocator(RouteLocatorBuilder builder) {
        return builder.routes().route(r -> r.
                //断言，判断条件
                path("/product/**")
                //目标uri，路由到微服务的地址
                .uri("lb://service-product")
                //注册自定义网关过滤器
                .filters(new CustomGatewayFilter())
                //路由id,唯一
                .id("product-service"))
                .build();



    }
}
